#!/usr/bin/env python
# coding=utf-8


import wsgiref.handlers


from google.appengine.ext import webapp
import xml.etree.ElementTree as etree

from django.utils import simplejson

class MainHandler(webapp.RequestHandler):

  def get(self):
    xml = """
<test>
  <name>sample name</name>
  <desc type='text'>sample desc</desc>
  <option>
    <value>value1</value>
  </option>
  <option>
    <value>value2</value>
  </option>
  <option>
    <value>value3</value>
  </option>
</test>
    """

    elem = etree.fromstring(xml)
    self.response.out.write( '<br />name=' +  elem.findtext('name') )
    self.response.out.write( '<br />desc=' + elem.findtext('desc'))
    self.response.out.write( '<br />desc=' + elem.find('desc').text)
    self.response.out.write( '<br />desc type=' + elem.find('desc').get('type') )

    for opt in elem.findall('option'):
      self.response.out.write('<br />option ' + opt.find('value').text )   
 


def main():
  application = webapp.WSGIApplication([('/xml', MainHandler)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()
